package com.itheima.tanhua.member.controller;

import com.itheima.tanhua.base.DTO.LoginDTO;
import com.itheima.tanhua.base.common.Result;
import com.itheima.tanhua.base.entity.ThMembers;
import com.itheima.tanhua.member.service.TdlFollowService;
import com.itheima.tanhua.member.service.TdlUsersService;
import com.itheima.tanhua.member.service.ThMembersService;
import com.itheima.tanhua.member.service.ThRecommendationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.crypto.interfaces.PBEKey;

/**
 * <p>
 * 会员表 前端控制器
 * </p>
 *
 * @author yangjiahao
 * @since 2023-01-30
 */
@Slf4j
@RestController
@RequestMapping("/members")
public class ThMembersController {

    @Autowired
    private ThMembersService thMembersService;

    @Autowired
    private TdlFollowService tdlFollowService;

    @Autowired
    private ThRecommendationService thRecommendationService;

    @PostMapping("sms")
    public Result sendMessage(@PathVariable String phone){
        thMembersService.sendMessage(phone);
        return Result.success("短信发送成功");
    }

    @PostMapping("login")
    public Result login(@RequestBody LoginDTO loginDTO){
        return thMembersService.login(loginDTO);
    }

    @PutMapping("info")
    public Result info(@RequestBody ThMembers thMembers){
        return thMembersService.info(thMembers);
    }

    @PostMapping("like")
    public Result like(@RequestBody String userId){
        return tdlFollowService.like(userId);
    }

    @DeleteMapping("like/{userid}")
    public Result disLike(@RequestBody String userId){
        return tdlFollowService.disLike(userId);
    }

    @GetMapping("recommendation/{longitude}/{latitude}")
    public Result redisGeo(@PathVariable Double longitude,@PathVariable Double latitude){
        return thRecommendationService.redisGeo(longitude,latitude);
    }

}
